<template>
	<view class="message-list">
		<view class="overtime-list-wrapper">
		<view v-if="commitInfo.length" class="list-wrapper"></view>
			<view v-else class="no-data-box">-- 暂无数据 --</view>
			</view>
		<view class="list-box" v-for="(item,index) in commitInfo" :key="index">
			<view class="list-box-title">
				<text :class="item.isRead!=0?'list-box-title-read has-read':'list-box-title-read no-read'">编号:{{item.id}}<!-- {{item.isRead!=0 ? '已读' : '未读'}} --></text>
				<text class="list-box-title-right">{{item.createTime||''}}</text>
			</view>
			<view class="list-box-content">
			<text class="list-box-content-right">{{item.msg}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import api from '../../api.js';
	export default {
		data() {
			return {
				userinfo: uni.getStorageSync('user'),
				commitInfo: [],
				readIndex: -1
			};
		},
		methods: {
			goDetail(item, index) {
				//类型 0 系统通知，
				var that=this;
				uni.navigateTo({
					url: '../message/message-detail?id='+item.id
				});
				
				if (item.read) {
					this.readIndex = -1;
				} else {
					this.readIndex = index;
				}
			}
		},
		mounted() {
			var that=this;
			api.post({
				url: 'api/getMessage.do',
				data: {userId:that.userinfo.id},
				success(res) {
					that.commitInfo=res.data;
				}
			})
		},
		onLoad() {
			this.readIndex = -1;
		},
		onShow() {
			// 判断readIndex , 如果不为 -1,重新请求数据，改变列表显示
			// 具体是重新请求数据,还是前端直接处理,需要商量
			// 这是前端直接处理,不请求后台
			if (this.readIndex !== -1) {
				this.commitInfo[this.readIndex].read = true;
			}
		}
	}
</script>

<style lang="scss">
	.message-list {
		margin: 20upx;

		.list-box {
			background: #fff;
			margin-bottom: 20upx;
			border-radius: 10upx;
			font-size: 24upx;
			padding: 20upx;

			&-title {
				font-size: 32upx;
				line-height: 60upx;
				display: flex;
				justify-content: space-between;

				&-read {
					line-height: 40upx;
					height: 40upx;
					margin: 10upx 10upx 10upx 0;
					font-size: 24upx;
					padding: 0 10upx;

					&.has-read {
						color: #1AAD19;
						position: relative;
					}

					&.has-read:after {
						content: '';
						width: 200%;
						height: 200%;
						position: absolute;
						top: 0;
						left: 0;
						border: 1px solid #1AAD19;
						border-radius: 20upx;
						-webkit-transform: scale(0.5, 0.5);
						transform: scale(0.5, 0.5);
						-webkit-transform-origin: top left;
					}

					&.no-read {
						color: #FF0000;
						position: relative;
					}

					&.no-read:after {
						content: '';
						width: 200%;
						height: 200%;
						position: absolute;
						top: 0;
						left: 0;
						border: 1px solid #FF0000;
						border-radius: 20upx;
						-webkit-transform: scale(0.5, 0.5);
						transform: scale(0.5, 0.5);
						-webkit-transform-origin: top left;
					}
				}

				&-left {
					flex: 1;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}

				&-right {
					font-size: 24upx;
					margin-left: 10upx;
				}
			}

			&-content {
				display: flex;
				padding-top: 10upx;
				line-height: 40upx;

				&-left {}

				&-right {
					flex: 1;
					text-overflow: ellipsis;
					overflow: hidden;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}
			}
		}
	}
</style>
